
<%@ page import="condicao.CondicaoDeCompra" %>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="layout" content="main" />
  <g:set var="entityName" value="${message(code:'condicaoDeCompra.label', default:'CondicaoDeCompra')}" />
  <title>Edit ${entityName}</title>
  <script>
  function mascara(o,f){
  v_obj=o
  v_fun=f
  setTimeout("execmascara()",1)
}

function execmascara(){
  v_obj.value=v_fun(v_obj.value)
}

function soNumeros(v){
  return v.replace(/\D/g,"")
}

function financeiro(v){
  v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
  v=v.replace(/(\d{1,3})(\d{2})/,"$1,$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
  //v=v.replace(/(\d{1,3})(\d{2})/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
  return v
}

function metodo(){
var ehFixo = document.getElementById('tforma_parcelamento_chk');
if(ehFixo.value != "B"){
    document.getElementById('tdia_vencimento1').value = ""
    document.getElementById('tdia_vencimento1').disabled = true
    document.getElementById('tdia_vencimento2').value = ""
    document.getElementById('tdia_vencimento2').disabled = true
}
else{
    document.getElementById('tdia_vencimento1').disabled = false
    document.getElementById('tdia_vencimento2').disabled = false
}
}

  </script>
</head>
<body>
  <div class="nav">
    <span class="menuButton"><a class="home" href="${resource(dir:'')}">Home</a></span>
    <span class="menuButton"><g:link class="list" action="list">${entityName} List</g:link></span>
    <span class="menuButton"><g:link class="create" action="create">New ${entityName}</g:link></span>
  </div>
  <div class="body">
    <h1>Edit ${entityName}</h1>
    <g:if test="${flash.message}">
      <div class="message">${flash.message}</div>
    </g:if>
    <g:hasErrors bean="${condicaoDeCompraInstance}">
      <div class="errors">
        <g:renderErrors bean="${condicaoDeCompraInstance}" as="list" />
      </div>
    </g:hasErrors>
    <g:form method="post" >
<%//<input type="hidden" name="id" value="${condicaoDeCompraInstance?.tcodigo_pk}" />%>
<%//<input type="hidden" name="version" value="${condicaoDeCompraInstance?.version}" />%>
      <div class="dialog">
        <table>
          <tbody>

            <tr class="prop">
              <td valign="top" class="name">
                <label for="tdescricao">
                  <g:message code="condicaoDeCompra.tdescricao.label" default="Tdescricao" />
                </label>

              </td>
              <td valign="top" class="value ${hasErrors(bean:condicaoDeCompraInstance,field:'tdescricao','errors')}">
                <input type="text" maxlength="30" id="tdescricao" name="tdescricao" value="${fieldValue(bean:condicaoDeCompraInstance,field:'tdescricao')}"/>
              </td>
            </tr>

            <tr class="prop">
              <td valign="top" class="name">
                <label for="tforma_parcelamento_chk">
                  <g:message code="condicaoDeCompra.tforma_parcelamento_chk.label" default="Tformaparcelamentochk" />
                </label>

              </td>
              <td valign="top" class="value ${hasErrors(bean:condicaoDeCompraInstance,field:'tforma_parcelamento_chk','errors')}">
          <g:select onblur="metodo()" id="tforma_parcelamento_chk" name="tforma_parcelamento_chk" from="['A', 'B', 'C']" value="${condicaoDeCompraInstance.tforma_parcelamento_chk}" ></g:select>
          A - Parcelado Normal, B - Prazo Fixo, C - Prazo Diferenciado
          </td>
          </tr>

          <tr class="prop">
            <td valign="top" class="name">
              <label for="tpossui_entrada_chk">
                <g:message code="condicaoDeCompra.tpossui_entrada_chk.label" default="Tpossuientradachk" />
              </label>

            </td>
            <td valign="top" class="value ${hasErrors(bean:condicaoDeCompraInstance,field:'tpossui_entrada_chk','errors')}">
          <g:select id="tpossui_entrada_chk" name="tpossui_entrada_chk" from="['S', 'N']" value="${condicaoDeCompraInstance.tpossui_entrada_chk}" ></g:select>
          </td>
          </tr>

          <tr class="prop">
            <td valign="top" class="name">
              <label for="tgrupo_comissao_fk">
                <g:message code="condicaoDeCompra.tgrupo_comissao_fk.label" default="Tgrupocomissaofk" />
              </label>

            </td>
            <td valign="top" class="value ${hasErrors(bean:condicaoDeCompraInstance,field:'tgrupo_comissao_fk','errors')}">
              <input disabled="true" type="text" id="tgrupo_comissao_fk" name="tgrupo_comissao_fk" value="${fieldValue(bean:condicaoDeCompraInstance,field:'tgrupo_comissao_fk')}" />
          <g:actionSubmit action="searchGrupo" value="Buscar" />
          </td>
          </tr>

<%/*<tr class="prop">
<td valign="top" class="name">
<label for="tparcela_pk">
<g:message code="condicaoDeCompra.tparcela_pk.label" default="Tparcelapk" />
</label>

</td>
<td valign="top" class="value ${hasErrors(bean:condicaoDeCompraInstance,field:'tparcela_pk','errors')}">
<input type="text" id="tparcela_pk" name="tparcela_pk" value="${fieldValue(bean:condicaoDeCompraInstance,field:'tparcela_pk')}" />
</td>
</tr>*/%>

          <tr class="prop">
            <td valign="top" class="name">
              <label for="tnum_dias_vencimento">
                <g:message code="condicaoDeCompra.tnum_dias_vencimento.label" default="Tnumdiasvencimento" />
              </label>

            </td>
            <td valign="top" class="value ${hasErrors(bean:condicaoDeCompraInstance,field:'tnum_dias_vencimento','errors')}">
              <input type="text" maxlength="8" onkeypress="mascara(this,soNumeros)" id="tnum_dias_vencimento" name="tnum_dias_vencimento" value="${fieldValue(bean:condicaoDeCompraInstance,field:'tnum_dias_vencimento')}" />
            </td>
          </tr>

          <tr class="prop">
            <td valign="top" class="name">
              <label for="tpercentual_parcela">
                <g:message code="condicaoDeCompra.tpercentual_parcela.label" default="Tpercentualparcela" />
              </label>

            </td>
            <td valign="top" class="value ${hasErrors(bean:condicaoDeCompraInstance,field:'tpercentual_parcela','errors')}">
              <input type="text" maxlength="6" onkeypress="mascara(this, financeiro)" id="tpercentual_parcela" name="tpercentual_parcela" value="${fieldValue(bean:condicaoDeCompraInstance,field:'tpercentual_parcela')}" />
            </td>
          </tr>

<%/*
<tr class="prop">
<td valign="top" class="name">
<label for="tcodigo_pk">
<g:message code="condicaoDeCompra.tcodigo_pk.label" default="Tcodigopk" />
</label>

</td>
<td valign="top" class="value ${hasErrors(bean:condicaoDeCompraInstance,field:'tcodigo_pk','errors')}">
<input type="text" id="tcodigo_pk" name="tcodigo_pk" value="${fieldValue(bean:condicaoDeCompraInstance,field:'tcodigo_pk')}" />
</td>
</tr>*/%>

          <tr class="prop">
            <td valign="top" class="name">
              <label for="tdia_vencimento1">
                <g:message code="condicaoDeCompra.tdia_vencimento1.label" default="Tdiavencimento1" />
              </label>

            </td>
            <td valign="top" class="value ${hasErrors(bean:condicaoDeCompraInstance,field:'tdia_vencimento1','errors')}">
              <input type="text" disabled="true" maxlength="8" onkeypress="mascara(this,soNumeros)" id="tdia_vencimento1" name="tdia_vencimento1" value="${fieldValue(bean:condicaoDeCompraInstance,field:'tdia_vencimento1')}" />
            </td>
          </tr>

          <tr class="prop">
            <td valign="top" class="name">
              <label for="tdia_vencimento2">
                <g:message code="condicaoDeCompra.tdia_vencimento2.label" default="Tdiavencimento2" />
              </label>

            </td>
            <td valign="top" class="value ${hasErrors(bean:condicaoDeCompraInstance,field:'tdia_vencimento2','errors')}">
              <input type="text" disabled="true" maxlength="8" onkeypress="mascara(this,soNumeros)" id="tdia_vencimento2" name="tdia_vencimento2" value="${fieldValue(bean:condicaoDeCompraInstance,field:'tdia_vencimento2')}" />
            </td>
          </tr>

          </tbody>
        </table>
      </div>
      <div class="buttons">
        <input type="hidden" name="id" value="${condicaoDeCompraInstance?.tparcela_pk}" />
        <span class="button"><g:actionSubmit class="save" value="Update" /></span>
        <!--<span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete" /></span>-->
        <span class="button"><g:actionSubmit class="save" action="atualizarParcela" value="Atualiza Parcela" /></span>
        <span class="button"><g:actionSubmit class="save" action="insereParcelaNoEdit" value="Insere Parcela" /></span>
      </div>
      <div class="list">
        <table>
          <thead>
            <tr>

          <g:sortableColumn property="tparcelaPk" title="${message(code:'condicaoDeCompra.tparcela_pk.label', default:'N°')}" />

          <g:sortableColumn property="tpercentual_parcela" title="${message(code:'condicaoDeCompra.tpercentual_parcela.label', default:'% parcela')}" />

          <g:sortableColumn property="tnum_dias_vencimento" title="${message(code:'condicaoDeCompra.tnum_dias_vencimento.label', default:'Nº Dias Vencimento')}" />

          <g:sortableColumn property="tdia_vencimento1" title="${message(code:'condicaoDeCompra.tdia_vencimento1.label', default:'Dia vencimento 1')}" />

          <g:sortableColumn property="tdia_vencimento2" title="${message(code:'condicaoDeCompra.tdia_vencimento2.label', default:'Dia vencimento 2')}" />

          <g:sortableColumn property="updateParcela" title="Operações" />

          </tr>
          </thead>
          <tbody>
          <g:each in="${condicaoDeCompraInstanceList}" status="i" var="condicaoDeCompraInstance">
            <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">

<%//<td><g:link action="show" id="${condicaoDeCompraInstance.tparcela_pk}">${fieldValue(bean:condicaoDeCompraInstance, field:'tparcela_pk')}</g:link></td>%>

              <td>${fieldValue(bean:condicaoDeCompraInstance, field:'tparcelaPk')}</td>

              <td>${fieldValue(bean:condicaoDeCompraInstance, field:'tpercentualParcela')}</td>

              <td>${fieldValue(bean:condicaoDeCompraInstance, field:'tnumDiasVencimento')}</td>

              <td>${fieldValue(bean:condicaoDeCompraInstance, field:'tdiaVencimento1')}</td>

              <td>${fieldValue(bean:condicaoDeCompraInstance, field:'tdiaVencimento2')}</td>

              <td>
            <g:link action="alterarParcela" id="${condicaoDeCompraInstanceList.indexOf(condicaoDeCompraInstance)}">Alterar</g:link>
            <g:link action="deletarParcela" id="${condicaoDeCompraInstanceList.indexOf(condicaoDeCompraInstance)}">Deletar</g:link>
            </td>

            </tr>
          </g:each>
          </tbody>
        </table>
      </div>
      <div class="paginateButtons">
        <g:if test="${condicaoDeCompraInstanceList == null}">
          <g:paginate total="0" />
        </g:if>
        <g:else>
          <g:paginate total="${condicaoDeCompraInstanceList.size()}" />
        </g:else>
      </div>
    </g:form>
  </div>
</body>
</html>
